package com.lebang.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lebang.component.RedisClient;
import com.lebang.domain.AppVideoSort;
import com.lebang.example.AppVideoSortExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 签到策略配置
 *
 * @Author hwq
 * @Date 2020-02-27
 */

@Service
public class AppVideoSortService extends BaseService<AppVideoSort, Integer, AppVideoSortExample> {
    @Autowired
    private RedisClient redisClient;

    private static final String KEY = "AppVideoSort";

    public String getKey() {
        return KEY;
    }

    public String getByCount(Integer count) {
        return redisClient.hget(KEY, count.toString());
    }

    public void init() {
        List<AppVideoSort> appVideoSorts = this.selectByExample(new AppVideoSortExample());
        appVideoSorts.forEach(s -> {
            //测试todo
            //redisClient.hset(KEY, s.getCount().toString(), JSON.toJSONString(s));
            redisClient.hset(KEY, s.getCount().toString(), s.getVideoKey());
        });
    }
}
